﻿using WRJClient.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WRJClient.Model;
using WRJClient.ViewModel;

namespace WRJClient.DAL
{
    public sealed class DataLoader
    {
        private static readonly DataLoader _instance = new DataLoader();
        public static DataLoader Instance { get { return _instance; } }
        private DataLoader() { }

        public async void LoadControlCenter()
        {
            List<WorkStationModel> models = await Task.Run(() => Api.GetAllControlCenter());
            ControlCenterManager.Instance.RemoveAll();
            foreach (var model in models)
            {
                ControlCenterManager.Instance.Add(new ControlCenterViewModel(model));
            }
        }
        public async void LoadUAV()
        {
            List<UAVModel> models = await Task.Run(() => Api.GetAllUAV());
            UAVManager.Instance.RemoveAll();
            foreach (var model in models)
            {
                UAVManager.Instance.Add(new UAVViewModel(model));
            }
        }
        public async void LoadWorkStation()
        {
            List<WorkStationModel> models = await Task.Run(() => Api.GetAllWorkStation());
            WorkStationManager.Instance.RemoveAll();
            foreach (var model in models)
            {
                WorkStationManager.Instance.Add(new WorkStationViewModel(model));
            }
        }
        public async void LoadMission()
        {
            List<MissionModel> models = await Task.Run(() => Api.GetAllMission());
            MissionManager.Instance.RemoveAll();
            foreach (var model in models)
            {
                MissionManager.Instance.Add(new MissionViewModel(model));
            }
        }
        public async void LoadAirline()
        {
            List<AirlineModel> models = await Task.Run(() => Api.GetAllAirline());
            AirlineManager.Instance.RemoveAll();
            foreach (var model in models)
            {
                AirlineManager.Instance.Add(new AirlineViewModel(model));
            }
        }
        public async void LoadInfomation()
        {
            List<InfomationModel> models = await Task.Run(() => Api.GetAllInfomation());
            InfomationManager.Instance.RemoveAll();
            foreach (var model in models)
            {
                InfomationManager.Instance.Add(new InfomationViewModel(model));
            }
        }
        public async void LoadZone()
        {
            List<ZoneModel> models = await Task.Run(() => Api.GetAllZone());
            ZoneManager.Instance.RemoveAll();
            foreach (var model in models)
            {
                ZoneManager.Instance.Add(new ZoneViewModel(model));
            }
        }
    }
}
